package spms.front.controller;

import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import spms.data.SpmsDataRemoteApi;
import spms.data.entity.User;
import spms.util.Page;

import javax.annotation.Resource;

@Api(tags = "User")
@Controller
public class UserController {

    @Resource
    SpmsDataRemoteApi spmsDataRemoteApi;

    /**
     * AJAX
     **/
    @PostMapping("getUserList")
    @ResponseBody
    public Object getUserList() {
        return spmsDataRemoteApi.findUserAll();
    }

    /**
     * 跳转菜单列表页面
     */
    @GetMapping("/userList")
    public Object getUserList(@RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, Model model) {
        userList(pageNum, pageSize, model);
        return "userList";
    }

    @PostMapping("/userList")
    public Object userList(@RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, Model model) {

        Page<User> page = spmsDataRemoteApi.findUserPage(pageNum, pageSize);

        model.addAttribute("page", page);
        return "userList::userList";
    }
}
